import React from 'react'
import { Upload, message, Button } from 'antd'
import { connect } from 'react-redux'
import { saveSlides } from '../../../store/actions'

/* eslint-disable */
function Index(props) {
    const uploadProps = {
        name: 'avatar',
        action: '/upload',
        headers: {
            authorization: localStorage.getItem('token'),
        },
        onChange(info) {
            if (info.file.status !== 'uploading') {
                console.log(info.file, info.fileList)
            }
            if (info.file.status === 'done') {
                message.success(`${info.file.name} file uploaded successfully`)
                // 
                console.log('上传成功！！', info)
                let fileList = {
                    url: info.file.response.url,
                    filename: info.file.response.filename
                }
                props.saveSildes(fileList)
            } else if (info.file.status === 'error') {
                message.error(`${info.file.name} file upload failed.`)
            }
        },
    }
    return (
        <div>
            <div>
                <Button>点击上传</Button>
                <Upload {...uploadProps}>
                    <Button >Click to Upload</Button>
                </Upload>
            </div>
        </div>
    )
}
const mapStateToProps = (store) => {
    return {}
}
const mapDispatchToProps = (dispatch) => {
    return {
        saveSildes(fileList) {
            dispatch(saveSlides(fileList))
        }
    }
}
export default connect(mapStateToProps, mapDispatchToProps)(Index)
